package com.token.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @auther: henriy
 * @Date: 2023/10/25
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ResultMessage<T> implements Serializable {

    private static final long serialVersionUID = 8088549247793678317L;

    private Integer code;

    private String message;

    private T data;

    public static ResultMessage isOk() {
        return ResultMessage.builder()
                .code(ResponseEnum.M2000.getCode())
                .message(ResponseEnum.M2000.getMessage())
                .build();
    }

    public static <T> ResultMessage isOk(T data) {
        return ResultMessage.builder()
                .code(ResponseEnum.M2000.getCode())
                .message(ResponseEnum.M2000.getMessage())
                .data(data)
                .build();
    }

    public static ResultMessage isOk(String msg) {
        return ResultMessage.builder()
                .code(ResponseEnum.M2000.getCode())
                .message(msg)
                .build();
    }

    public static <T> ResultMessage<T> errMsg(String msg, T data) {
        return new ResultMessage<T>(
                ResponseEnum.M4000.getCode(),
                msg,
                data
        );
    }

    public static <T> ResultMessage<T> errMsg(String msg) {
        return new ResultMessage<T>(
                ResponseEnum.M4000.getCode(),
                msg,
                null
        );
    }

    public static <T> ResultMessage<T> errMsg(int code, String msg) {
        return new ResultMessage<T>(
                code,
                msg,
                null
        );
    }

}
